from django.utils.deprecation import MiddlewareMixin
from django.http import JsonResponse
from apps.resp.response import ErrorResp
class ErrorHandleMiddleware(MiddlewareMixin):
    def process_exception(self, request, exception):
        # 统一处理异常
        if isinstance(exception,ErrorResp):
            return JsonResponse(exception.__dict__)
        else:
            return JsonResponse({
                "code":500,
                "message":"系统错误，请联系管理员:{}".format(exception),
                "data":{}
            })